<!DOCTYPE html>
<html>
<head>
<title>Module Develop</title>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
<style type="text/css">
	html,body{
		height: 100%
	}
	body{
		background-color: #fff;
	    margin: 0;
	}
	#wrap{
	    height: 100%;
	    position: relative;
	}
	#header{
		padding-top: 20px;
		background-color: #5082c2;
		height: 44px;
	    position: relative;
	}
	#header h1{
	    font-size: 20px;
	    height: 44px;
	    line-height: 44px;
	    margin: 0em;
	    color: #fff;
		margin-left: 100px;
		margin-right: 100px;
		text-align: center;
	}
    #main{
        display: block;
    }
    a.button{
        display: -webkit-box;
        -webkit-box-pack: center;
        -webkit-box-align: center;
        height: 36px;
        margin: 8px;
        background-color: rgba(240,240,240,1.0);
        border-color: rgba(220,220,220,1.0);
        border-width: 2px;
        border-style: solid;
	}
    a.active{
        background-color: rgba(240,240,240,0.6);
	}
</style>
</head>
<body>
	<div id="wrap">
	    <header id="header">
	    	<h1 id="title">模块开发</h1>
	    </header>
	    <div id="main">
            <a class="button" tapmode="active" onclick="initPrinter()">初始化</a>
            <a class="button" tapmode="active" onclick="connect()">连接设备</a>
            <a class="button" tapmode="active" onclick="print()">开始打印</a>
            <a class="button" tapmode="active" onclick="printLocal()">开始本地打印</a>
            <a class="button" tapmode="active" onclick="printString()">以字符串方式打印</a>
        </div>
    </div>
</body>
<script>

function printLocal(){
var printer = api.require('seblePrinter');
printer.printLocal({
                   path:'widget://res/print.html'

                   },function(ret,err){
                   if(ret){
                   alert(JSON.stringify(ret));
                   }
                   if(err){

                   alert(JSON.stringify(err));
                   }
                   });

}

function connect(){
    var printer = api.require('seblePrinter');
    printer.connect({
                    id : 0
                    },function(ret,err){

                    if(ret.message){
                    alert(ret.message);
                    }
                    if(err.message){
                    alert(err.message);
                    }
                    });
}
function print(){
     var printer = api.require('seblePrinter');
     printer.print({
                   url:'https://www.baidu.com'
                   },function(ret,err){

                   if(ret){
                   alert(JSON.stringify(ret));
                   }
                   if(err){

                   alert(JSON.stringify(err));
                   }
                   });
}

function initPrinter() {
    var printer = api.require('seblePrinter');

    printer.init(function(ret, err){
                 if(ret){
                 alert(JSON.stringify(ret));
                 }
                 if(err){

                 alert(JSON.stringify(err));
                 }
    });
}
    //说明：新接口不要调用正在审核
function printString() {

    var printString=new Array();
    printString[0] = {'type':1,'title':'测试电商','font':'big','textAlignment':'center'};
    printString[1] = {'type':2,'text':'测试电商服务中心(销售单)','textAlignment':'center'};
    printString[2] = {'type':3,'text':'RN3456789012'};

    printString[3] = {'type':4,'title':'时间:','text':'2016-04-27 10:01:50','offset':150};

    printString[4] = {'type':4,'title':'订单:','text':'4000020160427100150','offset':150};

    printString[5] = {'type':2,'text':'地址:深圳市南山区学府路东深大店','textAlignment':'left'};

    printString[6] = {'type':5};

    printString[7] = {'type':6,'leftText':'商品','middleText':'数量','rightText':'单价'};

    printString[8] = {'type':7,'leftText':'铅笔','middleText':'5','rightText':'2.0'};

    printString[9] = {'type':7,'leftText':'橡皮','middleText':'2','rightText':'1.0'};

    printString[10] = {'type':7,'leftText':'笔记本','middleText':'10','rightText':'5.0'};

    printString[11] = {'type':5};

    printString[12] = {'type':8,'title':'总计:','text':'62.0'};

    printString[13] = {'type':8,'title':'实收:','text':'100.0'};

    printString[14] = {'type':8,'title':'找零:','text':'48.0'};

    printString[15] = {'type':5};

    printString[16] = {'type':2,'text':'二维码','textAlignment':'center'};

    printString[17] = {'type':9,'QRCode':'www.baidu.com'};

    var printer = api.require('seblePrinter');
    printer.printString({
                        printString:printString
                        },function(ret,err){

                        if(ret){
                        alert(JSON.stringify(ret));
                        }
                        if(err){

                        alert(JSON.stringify(err));
                        }
                        });


}
function apiready() {

}
</script>
</html>
